home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997: The Complete Utilities Toolkit / macworld-complete-utilities-1997.iso / Programming / Pascal 2 C / p2c.txt < prev    next >
Encoding:
Text File  |  1995-02-17  |  3.8 KB  |  104 lines  |  [TEXT/MSWD]

  1. This archive contains p2c, a pascal to C translator. It reads from
  2. standard input and writes to standard output. That means that after
  3. you start the program, you must choose 'File' from the options below
  4. 'Standard Input' to select the pascal file, and 'file' from the
  5. options below 'Standard Output' to choose the C destination file.
  6.  
  7. P2C is *NOT* meant to do program development, and will only produce
  8. correct output if your pascal program conforms to ISO level 0
  9. pascal. If your input file does not conform to this standard, the
  10. program will quit, and will in many cases not produce an
  11. understandable error message. The program bails out at the first error
  12. message. The resulting output is not very comprehensible, unless you
  13. know what a static link is.
  14.  
  15. Usage on the macintosh for porting Mac applications written in pascal
  16. is thus a tricky job. Every function, type and constant that is not
  17. declared or defined will be considered an error. So, if you use e.g. a
  18. ToolBox routine like GetNextEvent, you will need to include a (empty)
  19. function definition for GetNextEvent, and write (part of) its data
  20. types as well. This can be quite a lot of work... Perhaps it is
  21. possible to adapt the program in such a way that it will skip
  22. declaration errors, but that would require a serious adapation of the
  23. source code. The source code is available on request, but was
  24. originally written in pascal and ported to c using p2c, so it is
  25. rather obscure.
  26.  
  27. I did not write the program, only port it to the mac. The original
  28. sources (also known as ptoc) must be available elsewhere.
  29.  
  30. Anyway, enjoy it.
  31.  
  32.     Theo Vosse
  33.     ----------
  34.     Unit for Experimental Psychology
  35.     University of Leiden
  36.     The Netherlands
  37.  
  38. PS Here is the original manual page:
  39.  
  40. --------------------------------------------------------------------------------
  41.  
  42.  
  43.  
  44.                                                                        P2C(1)
  45.  
  46.  
  47.  
  48.    NAME
  49.      p2c - Pascal to C translator
  50.  
  51.    SYNOPSIS
  52.      p2c < pascal source > c source
  53.  
  54.    DESCRIPTION
  55.      P2c reads a correct Pascal program and prints a C program with the same
  56.      behaviour.  It is intended as a tool for transporting finished applica-
  57.      tions to environments that lack Pascal compilers, it is not intended for
  58.      program development.
  59.  
  60.      The input should comply with the ISO level 0 Pascal definition.  Two
  61.      common Pascal extensions are also recognized: the keyword otherwise may
  62.      be used for default entries in case-statements, the keyword external may
  63.      be used in place of the forward directive to signify that a procedure or
  64.      function is defined in a library.  Furthermore, the translator does not
  65.      require a complete Pascal program, a consistent subset of declarations
  66.      can be translated.  Thus a primitive module concept is supported.
  67.  
  68.    SEE ALSO
  69.      P2c implementation notes.
  70.  
  71.    CAVEATS
  72.      The quality of an object program is of course highly dependent on the C
  73.      compiler that processes the translated code.  Arithmetic operations are
  74.      sometimes implemented in a way that is incompatible with the Pascal
  75.      definition.  For example, the translator assumes that:
  76.  
  77.           a := b mod c
  78.  
  79.      can be accurately translated into
  80.  
  81.           a = b % c
  82.  
  83.      but that may not be true if c is negative.  A check on the characteris-
  84.      tics of integer and float arithmetic is strongly recommended.
  85.  
  86.      Some Pascal constructs are impossible to express in C.  The translator
  87.      will not object to:
  88.  
  89.           type ptr = ^ ptr;
  90.  
  91.      but a C-compiler may balk at the resulting:
  92.  
  93.           typedef   ptr * ptr;
  94.  
  95.  
  96.    BUGS
  97.      The program can't translate comments from Pascal to C.
  98.  
  99.      The translator does not do complete typechecking so a Pascal program
  100.      that isn't formally correct may cause malfunction.
  101.  
  102.      Passing a procedure as parameter to an enclosing recursive procedure may
  103.      produce erroneous code (see the implementation notes).
  104.